#ifndef _applation_h_
#define _applation_h_
#include "GlutBase.h"
#include "GlutScene.h"
template<class SceneT>
class GlutApplacation
{
public:
	void init(char*title,int x,int y,int w, int h,GLenum mode = GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
	void run();

protected:
	static void reshape(int w,int h)
	{
		mScene->getWnd()->onSize(w,h);
	}


	static void render()
	{
		mScene->update();
		mScene->render();
		mScene->getWnd()->render();
	}
	static void specialKey(int c,int x,int y)
	{

	}
private:
	static GlutScene * mScene;
};


template<class SceneT>
void GlutApplacation<SceneT>::init(char*title,int x,int y,int w, int h,GLenum mode)
{
	int argc = 0;
	char**argv=NULL;
	glutInit(&argc,argv);
	glutInitDisplayMode(mode);
	mScene = new SceneT(new GlutWindow(title,w,h));
	glutInitWindowPosition(x,y);
	glutCreateWindow(title);
	glutDisplayFunc(render);
	glutReshapeFunc(reshape);
	glutSpecialFunc(specialKey);
}

#endif